package com.breeze.components.task.lock;

import java.util.Date;

/**
 * @author breeze
 */
public class LockScheduledUtil {

  /** 获取下次调度时间 */
  public static Date generateNextValidTime(
      ScheduleType scheduleType, String scheduleConf, Date fromTime) throws Exception {
    if (ScheduleType.CRON == scheduleType) {
      return new CronExpression(scheduleConf).getNextValidTimeAfter(fromTime);
    } else if (ScheduleType.FIXED_RATE == scheduleType
        || ScheduleType.FIXED_DELAY == scheduleType) {
      return new Date(fromTime.getTime() + Integer.parseInt(scheduleConf));
    }
    return new Date();
  }
}
